package com.fuda.trade.model
import org.junit.jupiter.api.Test

import org.junit.jupiter.api.Assertions

class TradeOrderUnitTest {
    @Test
    fun deserializeListIsCorrect() {
        val jsonString = """
         [{"id":{"tb":"trade_order","id":{"String":"01J5WJ6GQQPC93RR21DGYJ4ESC"}},"trade_bot_id":"j78ljefdnmwpll5hun8b","kline_id":"kline_id2","security_id":"security_id001","strategry_id":"strategy_id001","klt":"DAY","klts":"2020-01-03T00:00:00Z","klvolume":null,"data":{"type":"com.fuda.trade.model.TradeOrderData.Buy","security_name":"贵州茅台","security_code":"SH.STK.600519","pricing_type":"Limit","price":500.0,"volume":500,"desc":"Publish1@trade_order.rs","is_auto":false},"last_updated":"7405873267693167840/30201"},
         {"id":{"tb":"trade_order","id":{"String":"01J5WJ6GQNZ1BNY03JC8GKY61B"}},"trade_bot_id":"j78ljefdnmwpll5hun8b","kline_id":"kline_id1","security_id":"security_id001","strategry_id":"strategy_id001","klt":"DAY","klts":"2020-01-02T00:00:00Z","klvolume":null,"data":{"type":"com.fuda.trade.model.TradeOrderData.Buy","security_name":"贵州茅台","security_code":"SH.STK.600519","pricing_type":"Limit","price":500.0,"volume":500,"desc":"Publish1@trade_order.rs","is_auto":false},"last_updated":"7405873267682640864/30201"},
         {"id":{"tb":"trade_order","id":{"String":"01J5WJ6GQBHPNRN5KF6K61H74C"}},"trade_bot_id":"j78ljefdnmwpll5hun8b","kline_id":"kline_id0","security_id":"security_id001","strategry_id":"strategy_id001","klt":"DAY","klts":"2020-01-01T00:00:00Z","klvolume":null,"data":{"type":"com.fuda.trade.model.TradeOrderData.Buy","security_name":"贵州茅台","security_code":"SH.STK.600519","pricing_type":"Limit","price":500.0,"volume":500,"desc":"Publish1@trade_order.rs","is_auto":false},"last_updated":"7405873267641593872/30201"}] """
            .trimIndent()


        // Parse the JSON array into a list of TradeOrder objects
        val tradeOrders = TradeOrder.deserializeList(jsonString)
        Assertions.assertEquals(tradeOrders.size, 3)

        when (val data:TradeOrderData? = tradeOrders[2].data){
            is TradeOrderData.Buy -> Assertions.assertEquals(data.volume,500)
            else -> Assertions.assertEquals(true,false)
        }
    }
}